def prost(num):
    k = 0
    for i in range(2, num + 1):
        if num % i == 0:
            k += 1
    if k == 1 and num != 0 and num != 1:
        return True 
    else:
        return False
n = input()
list1 = []

for s in range(4):
    if prost(int(n[s])):
        list1.append(int(n[s]))
if prost(int(n[2:])):
    list1.append(int(n[2:]))
if prost(int(n[:2])):
    list1.append(int(n[:2]))
if prost(int(n[1:3])):
    list1.append(int(n[1:3]))
if prost(int(n[:3])):
    list1.append(int(n[:3]))
if prost(int(n[1:])):
    list1.append(int(n[1:]))
if prost(int(n)):
    list1.append(int(n))
if len(list1) > 0:
    print(max(list1))
else:
    print(0)
